// 首页
// http://web.chengxinzhijia.cn/

// 登录
// http://web.chengxinzhijia.cn/

// 接单
// http://ms.chengxinzhijia.cn/index.php/User/Task/ceshi

// {
//     "type": "object",
//     "data": {
//         "vuex_user": {
//             "status": 1,
//             "msg": "登录成功！",
//             "userid": "3142",
//             "username": "13766155987",
//             "is_spread": "0",
//             "app_flag": "app_web",
//             "isVoiceOpen": true,
//             "isShakeOpen": true
//         }
//     }
// }

function openHome() {
    let token = Android.getMap("token")
    if (!token) {
        return
    }
    let l = token.split(",")
    let obj = {
        "type": "object",
        "data": {
            "vuex_user": {
                "status": 1,
                "msg": "",
                "userid": l[0],
                "username": l[1],
                "is_spread": "0",
                "app_flag": "app_web",
                "isVoiceOpen": true,
                "isShakeOpen": true
            }
        }
    }
    localStorage.setItem("lifeData", JSON.stringify(obj))
}
openHome()


// 获取toke
function getAndroidToken() {
    let obj = JSON.parse(localStorage.getItem("lifeData"))
    obj = obj["data"]["vuex_user"]
    let userid = obj["userid"]
    let username = obj["username"]
    return userid + "," + username
}
getAndroidToken()



// 接单
function getParameterHandler() {
    let token = parameter.getMap("token")
    if (!token) {
        return
    }
    let l = token.split(",")
    let headers = {}
    let body = {
        "username": l[1],
        "userid": l[0]
    }
    let strUrl = ``
    let url = parameter.getMap("url") + strUrl
    return {
        mediaType: "form",
        requestType: "POST",
        url: url,
        headers: JSON.stringify(headers),
        body: JSON.stringify(body)
    }
}
getParameterHandler()



// 处理返回数据
function getResponse() {
    let res = response.getMap("res")
    res = JSON.parse(res)

    let code = "500"
    let message = res["msg"]
    if (res["status"] == 1) {
        code = "200"
    } else if (res["status"] == 3 || res["status"] == 100) {
        code = "500"
    } else {
        code = "300"
    }
    let decodedStr = message.replace(/\\u([\d\w]{4})/gi, (match, p1) =>
        String.fromCharCode(parseInt(p1, 16))
    );
    return {
        code: code,
        message: decodedStr,
        dataKey: "",
        dataValue: ""
    }
}
getResponse()

// {"msg":"\u62b1\u6b49\uff0c\u6682\u65e0\u8ba2\u5355\u3002","status":100}